/**
 * 全局组建
 */

import { DeviceEventEmitter } from 'react-native';

import { GLOBAL_MODEL, GLOBAL_TOOLTIP, GLOBAL_LOADING } from '../constant';
import { Model } from '../components/Modal';
import { ToolTipData } from '../components/ToolTip';

// 打开模态框
export const modalOpen = (params: Model): void => {
  DeviceEventEmitter.emit(GLOBAL_MODEL, { ...params, visible: true });
};

// 关闭模态框
export const modalClose = (): void => {
  DeviceEventEmitter.emit(GLOBAL_MODEL, { visible: false });
};

// 打开文本提示框
export const toolTipOpen = (params: ToolTipData): void => {
  DeviceEventEmitter.emit(GLOBAL_TOOLTIP, { ...params, visible: true });
};

// loading 打开/关闭
export const loading = {
  show: (needBack: boolean = true): void =>
    DeviceEventEmitter.emit(GLOBAL_LOADING, { visible: true, needBack }),
  hide: (): void => DeviceEventEmitter.emit(GLOBAL_LOADING, { visible: false })
};
